package com.orange.common.base.entity;

import java.io.Serializable;
import java.util.UUID;

public class ReqHeader implements Serializable {
    private static final long serialVersionUID = 3944374784561672805L;

    private long requestTimestamp;
    private String requestSequenceNo;
    private String ip;

    // 私有构造函数
    private ReqHeader(Builder builder) {
        this.requestTimestamp = builder.requestTimestamp;
        this.requestSequenceNo = builder.requestSequenceNo;
        this.ip = builder.ip;
    }

    // Getter方法
    public long getRequestTimestamp() {
        return requestTimestamp;
    }

    public String getRequestSequenceNo() {
        return requestSequenceNo;
    }

    public String getIp() {
        return ip;
    }

    @Override
    public String toString() {
        return "ReqHeader{" +
                "requestTimestamp=" + requestTimestamp +
                ", requestSequenceNo='" + requestSequenceNo + '\'' +
                ", ip='" + ip + '\'' +
                '}';
    }

    // 建造者类
    public static class Builder {
        private long requestTimestamp;
        private String requestSequenceNo;
        private String ip;

        // 默认构造函数
        public Builder() {
            this.requestTimestamp = System.currentTimeMillis();
            this.requestSequenceNo = UUID.randomUUID().toString();
            // IP默认留空，可能需要从上下文中获取
            this.ip = "0.0.0.0";
        }

        // 复制构造函数
        public Builder(ReqHeader header) {
            this.requestTimestamp = header.requestTimestamp;
            this.requestSequenceNo = header.requestSequenceNo;
            this.ip = header.ip;
        }

        public Builder requestTimestamp(long requestTimestamp) {
            this.requestTimestamp = requestTimestamp;
            return this;
        }

        public Builder requestSequenceNo(String requestSequenceNo) {
            this.requestSequenceNo = requestSequenceNo;
            return this;
        }

        public Builder ip(String ip) {
            this.ip = ip;
            return this;
        }

        public ReqHeader build() {
            return new ReqHeader(this);
        }
    }

    // 静态方法：创建建造者
    public static Builder builder() {
        return new Builder();
    }

    // 静态方法：从现有header创建建造者
    public static Builder builder(ReqHeader header) {
        return new Builder(header);
    }

    // 静态方法：创建默认header
    public static ReqHeader createDefault() {
        return builder().build();
    }

    // 静态方法：创建带有IP的header
    public static ReqHeader createWithIp(String ip) {
        return builder().ip(ip).build();
    }


}
